package com.android.fragmentdemo.adapters
import android.app.Activity
import android.content.Context
import android.util.Log
import androidx.recyclerview.widget.RecyclerView
import com.android.fragmentdemo.CardItemActivity
import com.android.fragmentdemo.HorizontalCustomLayoutManagerActivity
import com.android.fragmentdemo.R
import com.android.fragmentdemo.ViewPager2UseActivity
import com.hengfoxwolf.commonbase.base.databeans.SlipItem
import com.android.fragmentdemo.databinding.RvCustomItemLayoutBinding
import com.android.fragmentdemo.databinding.RvSlipItemLayoutBinding
import com.android.fragmentdemo.databinding.RvStaggeredItemLayoutBinding
import com.android.fragmentdemo.startActivity
import com.hengfoxwolf.commonbase.base.adapter.BaseRvAdapter

class StaggeredLayoutManagerAdapter(private val activity: Activity, mBottomData: MutableList<Int>) : BaseRvAdapter<SlipItem, RvStaggeredItemLayoutBinding>() {

    private val bottomData = mBottomData

    override fun getLayoutId(): Int = R.layout.rv_staggered_item_layout

    override fun bindData(holder: ViewHolder, dataItem: SlipItem, position: Int) {
        val content = "${dataItem.number + 1}/${itemDataSet?.size ?: 0}"
        holder.binding.tvStaggeredContent.text = content
        holder.binding.rvStaggeredRoot.setBackgroundColor(activity.resources.getColor(dataItem.color))
        changeViewRootHeight(holder.binding, position)
    }

    private fun changeViewRootHeight(mBinding: RvStaggeredItemLayoutBinding,position: Int) {
        val layoutParams: RecyclerView.LayoutParams =
            mBinding.rvStaggeredRoot.layoutParams as RecyclerView.LayoutParams
        layoutParams.height = bottomData[position]
        mBinding.rvStaggeredRoot.layoutParams = layoutParams
    }
}